package com.hopu.blb_erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.TVehicle;
import com.hopu.blb_erp.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//

@Api
@RestController
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    @ApiOperation("查询所有的车辆")
    @GetMapping("/vehicles/{current}/{pageSize}")
    public ResponseEntity<PageEntity> findPage(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize,
                                               String vehicleName,String numberPlate){
        PageEntity<TVehicle> pages = vehicleService.findLogsPages(current, pageSize,vehicleName,numberPlate);
        return ResponseEntity.ok(pages);
    }

    @ApiOperation("查询所有车辆")
    @GetMapping("/vehicles")
    public ResponseEntity<List<TVehicle>> findAllVehicle(){
        List<TVehicle> vehicles = vehicleService.findAllVehicle();
        return ResponseEntity.ok(vehicles);
    }

    @ApiOperation("对车辆进行更新")
    @PostMapping("/vehicle")
    public ResponseEntity<String> maDrive(@RequestBody TVehicle vehicle){
        vehicleService.saveOrUpdate(vehicle);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("根据id进行删除车辆")
    @DeleteMapping("/vehicle/{id}")
    public ResponseEntity<String> removeDrive(@PathVariable Integer id){
        vehicleService.removeById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("通过配送id查询所有车辆")
    @GetMapping("/vehicle")
    public ResponseEntity<List<TVehicle>> findVehicleById(Integer logisticsId){
        List<TVehicle> vehicles = vehicleService.list(new QueryWrapper<TVehicle>().lambda().eq(TVehicle::getLogisticsId, logisticsId));
        return ResponseEntity.ok(vehicles);
    }

    @ApiOperation("通过驾驶员id查询车辆")
    @GetMapping("/vehicleId")
    public ResponseEntity<TVehicle> findById(Integer driverId){
        TVehicle vehicle = vehicleService.getById(driverId);
        return ResponseEntity.ok(vehicle);
    }
}
